<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>Title</title>
</head>
<body>
    <input type="button" onclick="request()" value="分析request"/>
    <hr>
    <p>发httppost请求目标网站会出现405 状态码，原因为 Apache、IIS、Nginx等绝大多数web服务器，都不允许静态文件响应POST请求</p>
    <p>所以将post请求改为get请求即可/将.html文件改为.jsp文件</p>
    <form action="http://192.168.1.5:8080/JavaServlet/requestParam" enctype="application/x-www-form-urlencoded" method="get">
        <input type="text" value="i am form table in field" name="inputNamesyg">
        <input type="checkbox" value="abc" name="有趣111"/>有趣
        <input type="checkbox" value="efg" name="有趣111"/>有趣
        <input type="file" name="file"/>
        <input type="submit" value="提交表单"/>
    </form>

</body>
<script>

    function request (){
        var url = "http://localhost:8082/JavaServlet/requestParam?product="+123;
        Ajax(url,function (){
            alert("获取成功");
        },
        function () {
            alert("获取失败");
        });
    }

    //Ajax对象
    function Ajax(url,successFn,failureFn){
        //1,创建Ajax对象
        if (window.XMLHttpRequest) {
            //非IE浏览器
            var oAjax = new XMLHttpRequest();
        }else{
            //IE浏览器
            var oAjax = new ActiveXObject("Microsoft.XMLHTTP");
        }

        //2,连接服务器
        oAjax.open("GET",url,true);

        //3,发送
        oAjax.send();

        //4,接收
        oAjax.onreadystatechange = function () {
            if (oAjax.readyState == 4) {
                if (oAjax.status == 200) {
                    //获取数据成功
                    successFn();
                }else{
                    //获取失败
                    failureFn();
                }
            }
        }
    }
</script>
</html>